<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>间歇调用</title>
    <script>
        let timer = null;
        function show(){
            let i = 0;
            //定时器
            timer = setInterval(function (){
                console.log(i++)
                document.getElementById("count").innerText = i;
                document.getElementById("now").innerText = new Date()
            },1000);
        }

        function stoptime(){
            clearInterval(timer)
        }
    </script>
</head>
<body>
    <h1>间歇调用--可以无限次</h1>
    <h2 id="count"></h2>
    <h2 id="now"></h2>
    <button onclick="show()">开始</button>
    <button onclick="stoptime()">停止</button>
</body>
</html>